const app = getApp()

Page({
  data: {
    //轮播图
    cardCur: 0,
    swiperList: [{
      id: 0,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84000.jpg'
    }, {
      id: 1,
        type: 'image',
        url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84001.jpg',
    }, {
      id: 2,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big39000.jpg'
    }, {
      id: 3,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg'
    }, {
      id: 4,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big25011.jpg'
    }, {
      id: 5,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big21016.jpg'
    }, {
      id: 6,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big99008.jpg'
    }],
    //导航栏
    TabCur: 0,
    scrollLeft:0,
    servers:[],
    tt: '',
    listArr:[],
    servers2:[]
  },
  adddetial: function () {
    wx.navigateTo({
      url: '/pages/xqfb/xqfb',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id-1)*60
    })
  },
  showModal(e) {
    this.setData({
      modalName: e.currentTarget.dataset.target
    })
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
  gridchange: function (e) {
    this.setData({
      gridCol: e.detail.value
    });
  },
  gridswitch: function (e) {
    this.setData({
      gridBorder: e.detail.value
    });
  },
  menuBorder: function (e) {
    this.setData({
      menuBorder: e.detail.value
    });
  },
  menuArrow: function (e) {
    this.setData({
      menuArrow: e.detail.value
    });
  },
  menuCard: function (e) {
    this.setData({
      menuCard: e.detail.value
    });
  },
  switchSex: function (e) {
    this.setData({
      skin: e.detail.value
    });
  },
  to(e){
    console.log(e);
    wx.navigateTo({
      url: '/pages/schoolxq/schoolxq?circleid='+e.currentTarget.dataset.circleid,
    })
  },
  onLoad: function () {
    console.log('userId',app.data.userInfo.userid);
    var listService = [
      {
        items: [
          {
          isBind: true,
          name: '校园圈子',
          url: 'xiaoq',
          icon: '/images/xyqz.png',
          code: '11'
        },
         {
          isBind: true,
          name: '失物招领',
          url: 'swzl',
          icon: '/images/swzl.png',
          code: '11'
        },
         {
          isBind: true,
          name: '吃食堂',
          url: 'shopfood',
          icon: '/images/fbdd.png',
          code: '11'
        },
        ]
      },
    ]

    var listService2 = [
      {
        items: [
          {
          isBind: true,
          name: '万能任务',
          url: 'powerTask',
          icon: '/images/万能搜索.png',
          code: '11'
        },
         {
          isBind: true,
          name: '取快递',
          url: 'expTask',
          icon: '/images/快递员_o.png',
          code: '11'
        },
         {
          isBind: true,
          name: '',
          url: '',
          icon: '',
          code: '11'
        },
        ]
      },
    ]

    this.setData({
      servers: listService,
      servers2: listService2
    })
    this.chaxun();
   },
  tosb(e){
    wx.navigateTo({
      url: '/pages/xiaoq/xiaoq',
    })
  },
  qunm(e){
    wx.navigateTo({
      url: '/pages/swzl/swzl',
    })
  },
  addlike(e){
    console.log(e);
     var that = this;
     wx.request({
       url: 'https://www.woodymidnight.cn/BCUHelper/api/circle/updatacirclelike',
       method: 'POST',
       data:{
         circleId : e.currentTarget.dataset.circleid
       },
       header: { 'content-type': 'application/x-www-form-urlencoded' },
       success: res => {
        // var resData = res.data;
        //  that.setData({
        //    listArr: resData.data
        //  })
        this.chaxun()
       }
     })
  },

  chaxun(){
    var that=this;
    wx.request({  
      url: 'https://www.woodymidnight.cn/BCUHelper/api/circle/selecallcircle',  
      method: 'POST',                                      
      header: { 'content-type': 'application/json' }, 
      success: function (res) {   
        var resData = res.data;
        var data = res.data.data ;
        console.log("数据" , resData);
        console.log("this:",this);
        for(let i = 0 ; i < data.length ; i++){
          data[i].circletime = that.toData(data[i].circletime)
        }
        that.setData({
          listArr: resData.data.reverse()
        })
      }
    })
  },

  bindNavigator: function (e) {
    wx.navigateTo({
      url: "/pages/"+e.currentTarget.dataset.path+"/"+e.currentTarget.dataset.path,
    })
  },

  toData : function(number){
    var n=number;
    var date = new Date(n);
    var Y = date.getFullYear() + '/';
    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '/';
    var D = date.getDate()<10 ? '0'+date.getDate() : date.getDate();
    return (Y+M+D)
  },

  onShow(e){
    this.chaxun();
  }
})
